import { reqAddress, reqCategorys, reqShops } from '../api/index'
import { RECEIVE_ADDRESS, RECEIVE_CATEGORYS, RECEIVE_SHOPS } from './mutation-types'

export default {
  /**
   * 异步获取地址
   * @param {*} param0 { commit, state }
   */
  async getAddress ({ commit, state }) {
    const geohash = state.latitude + ',' + state.longitude
    const result = await reqAddress(geohash)
    commit(RECEIVE_ADDRESS, { address: result.data })
  },

  /**
   * 异步获取分类列表
   * @param {*} param0 { commit }
   */
  async getCategorys ({ commit }) {
    const result = await reqCategorys()
    commit(RECEIVE_CATEGORYS, result.data)
  },

  /**
   * 异步获取商家列表
   * @param {*} param0 { commit, state }
   */
  async getShops ({ commit, state }) {
    const { latitude, longitude } = state
    const result = await reqShops({ latitude, longitude })
    commit(RECEIVE_SHOPS, result.data)
  }
}
